
project , uses(../data_output/legislators_klarner.dta)

	
	***********
	** Louisiana
	** Consecutive term limites: 3 x 4-year terms.
	** First year: 2007
	***********
	
	use ../data_output/legislators_klarner.dta, clear
	keep if state=="LA" 
	keep if regexm(term, "1996|1997|1999|2001|2003|2005|2007|2009|2011|2013|2015")
	gen lastname = trim(regexs(1)) if regexm(lower(CandName),"([^,]+)")
	gen firstname = trim(regexs(1)) if regexm(lower(CandName),",( [^ ]+)")
	gen mergename = lastname
	bys chamber mergename term: gen n = _n
	by chamber mergename term: egen mean_n=mean(n)
	replace mergename = firstname + " " +lastname if mean_n>1  //firstname  + " " +  lastname //firstname+ ". "
	drop n mean_n
	save ../data_output/legislators_LA_1997_2015.dta, replace	
	
	
	gen year_minus0 = year	
	gen year_minus4 = year-4
	gen year_minus8 = year-8
	tostring year_minus*, replace
	gen s = year_minus8+";"+year_minus4+";"+ year_minus0 + ";"
	gen termlimited = regexm(elections_won, s)==1 & year>=2003
	save ../data_output/legislators_LA_1997_2015.dta, replace	
project, creates(../data_output/legislators_LA_1997_2015.dta)	
	
	
project, original(../data_input/LA/la_bills.csv)	
	import delimited using ../data_input/LA/la_bills.csv,  clear  delimiters(";") bindquotes(strict) encoding("utf-8") varnames(1)
	gen inoffice = regexs(1) if regexm( session ,"([0-9]+)")
	gen term = ""
	replace term = "2016-2019" if regexm(inoffice, "2016|2017|2018|2019")	
	replace term = "2012-2015" if regexm(inoffice, "2012|2013|2014|2015")	
	replace term = "2008-2011" if regexm(inoffice, "2008|2009|2010|2011")	
	replace term = "2004-2007" if regexm(inoffice, "2004|2005|2006|2007")	
	replace term = "2000-2003" if regexm(inoffice, "2000|2001|2002|2003")	
	replace term = "1996-1999" if regexm(inoffice, "1996|1997|1998|1999")	
	replace term = "1992-1995" if regexm(inoffice, "1992|1993|1994|1995")	
	replace term = "1988-1991" if regexm(inoffice, "1988|1989|1990|1990")	
	
	replace sponsor = regexr( sponsor,",.*$", "")
	replace sponsor = trim(regexr( lower(sponsor),"ii|jr[.]?", ""))
	replace sponsor = subinstr(sponsor	, `"""',  "", .)
	
	gen mergename = regexs(1) if regexm(sponsor, "([^ ]+)$")
	replace mergename = subinstr(mergename, "-", "",.)
	replace mergename = "avery alexander" if regexm(sponsor, "avery c. alexander") & regexm(term, "1996")
	replace mergename = "rodney alexander" if regexm(sponsor, "rodney alexander") & regexm(term, "1996")
	replace mergename = "ernie alexander" if regexm(sponsor, "ernie alexander") & regexm(term, "2000")
	replace mergename = "rodney alexander" if regexm(sponsor, "rodney alexander") & regexm(term, "2000")
	replace mergename = "jack smith" if regexm(sponsor, "jack d. smith") & regexm(term, "1996|2000|2004")
	replace mergename = "john smith" if regexm(sponsor, "john r. smith") & regexm(term, "1996|2000|2004")
	replace mergename = "gary smith" if regexm(sponsor, "gary l. smith") & regexm(term, "2000|2004|2008")
	replace mergename = "jane smith" if regexm(sponsor, "jane h. smith") & regexm(term, "2000|2004|2008")
	replace mergename = "patricia smith" if regexm(sponsor, "patricia smith") & regexm(term, "2008")
	replace mergename = "whitewarrenfarve" if regexm(sponsor, "farve") & regexm(term, "1996")
	replace mergename = "dorseywelch" if regexm(sponsor, "welch") & regexm(term, "1996|2000")
	replace mergename = "dorseywelch" if regexm(sponsor, "yvonne dorsey") & regexm(term, "2004|2008")
	replace mergename = "dorseywelch" if regexm(sponsor, "yvonne dorsey-colomb") & regexm(term, "2012")
	replace mergename = "karen carter" if regexm(sponsor, "karen r. carter") & regexm(term, "2000|2004|2008")
	replace mergename = "robby carter" if regexm(sponsor, "robert carter") & regexm(term, "2000|2004")
	replace mergename = "steve carter" if regexm(sponsor, "steve carter") & regexm(term, "2008")
	replace mergename = "michael jackson" if regexm(sponsor, "michael jackson") & regexm(term, "2000|2008")
	replace mergename = "lydia jackson" if regexm(sponsor, "lydia p. jackson") & regexm(term, "2000")
	replace mergename = "girod jackson" if regexm(sponsor, "girod jackson") & regexm(term, "2008|2012")
	replace mergename = "katrina jackson" if regexm(sponsor, "katrina jackson") & regexm(term, "2012")
	replace mergename = "westonbroome" if regexm(sponsor, "sharon weston broome") & regexm(term, "2000|2004|2008|2012")
	replace mergename = "elcie guillory" if regexm(sponsor, "elcie j. guillory") & regexm(term, "2004")	
	replace mergename = "mickey guillory" if regexm(sponsor, "mickey guillory") & regexm(term, "2004|2008")
	replace mergename = "elbert guillory" if regexm(sponsor, "elbert l. guillory") & regexm(term, "2008")
	replace mergename = "mike powell" if regexm(sponsor, "mike powell") & regexm(term, "2004")
	replace mergename = "henry powell" if regexm(sponsor, "tank powell") & regexm(term, "2004")
	replace mergename = "jeffersonbullock" if regexm(sponsor, "jalila jefferson") & regexm(term, "2004")
	replace mergename = "saintgermain" if regexm(sponsor, "st. germain") & regexm(term, "2004|2008")
	replace mergename = "ashfordbarrow" if regexm(sponsor, "ashford barrow") & regexm(term, "2008|2012")
	replace mergename = "austin badon" if regexm(sponsor, "austin badon") & regexm(term, "2008")
	replace mergename = "bobby badon" if regexm(sponsor, "^badon") & regexm(term, "2008")
	replace mergename = "henry burns" if regexm(sponsor, "henry burns") & regexm(term, "2008|2012")
	replace mergename = "tim burns" if regexm(sponsor, "tim burns") & regexm(term, "2008|2012")	
	replace mergename = "jay morris" if regexm(sponsor, "jay morris") & regexm(term, "2012")
	replace mergename = "james morris" if regexm(sponsor, "jim morris") & regexm(term, "2012")
	replace mergename = "charles jones" if regexm(sponsor, "c.d. jones") & regexm(term, "2000")
	replace mergename = "rosalind jones" if regexm(sponsor, "rosalind d. jones") & regexm(term, "2008")
	replace mergename = "bill jones" if regexm(sponsor, "bill jones") & regexm(term, "2000")
	replace mergename = "sam jones" if regexm(sponsor, "sam jones") & regexm(term, "2008")
	replace mergename = "alfred williams" if regexm(sponsor, "alfred c. williams") & regexm(term, "2012")
	replace mergename = "patrick williams" if regexm(sponsor, "patrick williams") & regexm(term, "2012")
	replace mergename = "nancy landry" if regexm(sponsor, "nancy landry") & regexm(term, "2012")
	replace mergename = "terry landry" if regexm(sponsor, "terry landry") & regexm(term, "2012")
	replace mergename = "stuart bishop" if regexm(sponsor, "stuart j. bishop") & regexm(term, "2012")
	replace mergename = "wesley bishop" if regexm(sponsor, "wesley bishop") & regexm(term, "2012")
	replace mergename = "cleo fields" if regexm(sponsor, "cleo fields") & regexm(term, "2000")
	replace mergename = "wilson fields" if regexm(sponsor, "wilson fields") & regexm(term, "2000")
	replace mergename = "nick gautreaux" if regexm(sponsor, "nick gautreaux") & regexm(term, "2004|2008")
	replace mergename = "d. gautreaux" if regexm(sponsor, "butch gautreaux") & regexm(term, "2004|2008")
	replace mergename = "carterpeterson" if regexm(sponsor, "karen carter peterson") & regexm(term, "2012")
	
	merge m:1 chamber term mergename using ../data_output/legislators_LA_1997_2015.dta
	*12 observations do not merge
	drop if _merge==1
	drop _merge
	drop sponsor
	gen sponsor = 1 if bill!=""
	gen law = regexm(lower(status), "- act")	
	save ../data_output/bills_by_sponsor_LA_1997_2015.dta, replace	
project, creates(../data_output/bills_by_sponsor_LA_1997_2015.dta)	

	use ../data_output/bills_by_sponsor_LA_1997_2015.dta, clear
	collapse (sum) sponsor law (first) elections_* terms_in_office win TermLengthActual CandName district chamber state party mergename inoffice year termlimited vtsh, by(CandId term )	
	save ../data_output/total_bills_by_sponsor_LA_1997_2015.dta, replace	
project, creates(../data_output/total_bills_by_sponsor_LA_1997_2015.dta)		

	**Voting
	
	use ../data_output/legislators_klarner.dta, clear
	gen lastname = regexs(1) if regexm(lower(CandName),"([^,]+), [^!]")
	gen firstletter = regexs(1) if regexm(lower(CandName),"[^,]+, ([^ ])")
	keep if state=="LA" & chamber=="house"
	keep if regexm(term, "1996|2000|2004|2008|2012")
	gen os_mergename = ""
	replace os_mergename = lastname
	bys chamber os_mergename term: gen n = _n
	by chamber os_mergename term: egen mean_n=mean(n)
	replace os_mergename = lastname +", "+firstletter if mean_n>1  //firstname  + " " +  lastname //firstname+ ". "
	drop n mean_n
	tostring district , gen(Dist)
	bys chamber os_mergename term: gen n = _n
	by chamber os_mergename term: egen mean_n=mean(n)
	replace os_mergename = lastname +" "+firstletter+" " + Dist if mean_n>1  //firstname  + " " +  lastname //firstname+ ". "
	
	tempfile tmp
	save `tmp', replace
	
project, original(../data_input/LA/la_votes.csv)	
	import delimited using ../data_input/LA/la_votes.csv,  clear  delimiters(";") bindquotes(strict) encoding("utf-8") varnames(1)
	keep if chamber=="H"
	gen term = ""
	replace term = "2016-2019" if regexm(session, "2016|2017|2018|2019")	
	replace term = "2012-2015" if regexm(session, "2012|2013|2014|2015")	
	replace term = "2008-2011" if regexm(session, "2008|2009|2010|2011")	
	replace term = "2004-2007" if regexm(session, "2004|2005|2006|2007")	
	replace term = "2000-2003" if regexm(session, "2000|2001|2002|2003")	
	replace term = "1996-1999" if regexm(session, "1996|1997|1998|1999")
	replace name = subinstr(name, ".","",.)
	gen Name = name[_n]+name[_n+1]
	replace name = Name if regexm(name ,", $") | regexm(name ,"^Mc|^Mr. ") | name =="Le" | name =="La" | name =="De"
	replace name = name + name[_n+2] if regexm(name ,"Smith, J") & regexm(term, "2008")==0
	drop if regexm(name, "Total")
	gen os_mergename = trim(lower(name))
	replace os_mergename = subinstr(os_mergename,"’","",.)
	replace os_mergename = subinstr(os_mergename,"'","",.)
	replace os_mergename = subinstr(os_mergename,"-","",.)	
	replace os_mergename = subinstr(os_mergename,".",". ",.)
	replace os_mergename = subinstr(os_mergename,"  "," ",.)
	
	replace os_mergename = "alexander, a"	if os_mergename=="alexander, as93rd" & regexm(term, "1996")
	replace os_mergename = "alexander, r"	if os_mergename=="alexander, rs13th" & regexm(term, "1996")
	replace os_mergename = "dorseywelch"	if os_mergename=="welch" & regexm(term, "1996|2000")
	replace os_mergename = "dorseywelch"	if os_mergename=="dorsey" & regexm(term, "2004")
	replace os_mergename = "whitewarrenfarve"	if os_mergename=="farve" & regexm(term, "1996")
	replace os_mergename = "smith j 30"	if [ os_mergename=="smith, jrs30th" | os_mergename=="smith, jr30th"] & regexm(term, "1996")
	replace os_mergename = "smith j 50"	if os_mergename=="smith, jds50th" & regexm(term, "1996")
	replace os_mergename = "willardlewis"	if os_mergename=="willard" & regexm(term, "1996")
	replace os_mergename = "smith, g"	if os_mergename=="smith, gs56th" & regexm(term, "2000|2004")
	replace os_mergename = "smith j 8"	if os_mergename=="smith, jhs8th" & regexm(term, "2000|2004")
	replace os_mergename = "smith j 50"	if os_mergename=="smith, jds50th" & regexm(term, "2000|2004")
	replace os_mergename = "smith j 30"	if os_mergename=="smith, jrs30th" & regexm(term, "2000|2004")
	replace os_mergename = "smith j 8"	if os_mergename=="smith, jh8th" & regexm(term, "2004")
	replace os_mergename = "smith j 50"	if os_mergename=="smith, jd50th" & regexm(term, "2004")
	replace os_mergename = "smith j 30"	if os_mergename=="smith, jr30th" & regexm(term, "2004")
	replace os_mergename = "willardlewis"	if os_mergename=="willard" & regexm(term, "2000")
	replace os_mergename = "westonbroome"	if os_mergename=="broome" | os_mergename=="weston" & regexm(term, "2000")
	replace os_mergename = "saintgermain"	if os_mergename=="germain" & regexm(term, "2004|2008")
	replace os_mergename = "powell, h"	if os_mergename=="powell, t" & regexm(term, "2004")
	replace os_mergename = "jeffersonbullock"	if os_mergename=="jefferson" & regexm(term, "2004")
	replace os_mergename = "ashfordbarrow"	if os_mergename=="barrow" & regexm(term, "2008|2012")
	replace os_mergename = "carter, k"	if os_mergename=="carter" & regexm(term, "2008")
	replace os_mergename = "morris j 1"	if os_mergename=="morris, jim" & regexm(term, "2012")
	replace os_mergename = "morris j 14"	if os_mergename=="morris, jay" & regexm(term, "2012")
	
	replace os_mergename = "downer"	if os_mergename=="speaker" & regexm(term, "1996")
	replace os_mergename = "dewitt"	if os_mergename=="speaker" & regexm(term, "2000")
	replace os_mergename = "salter"	if os_mergename=="speaker" & regexm(term, "2004")
	replace os_mergename = "tucker"	if os_mergename=="speaker" & regexm(term, "2008")
	replace os_mergename = "kleckley"	if os_mergename=="speaker" & regexm(term, "2012")
	
	merge m:1  os_mergename term using `tmp'	
	* 5 obs not merging
	drop if _merge==1
	drop _merge	
	
	gen floorvotes = regexm(lower(vote), "yes|no")
	replace vote = "1" if regexm(lower(vote),"yes")
	replace vote = "-1" if regexm(lower(vote),"no")
	replace vote = "0" if vote!="1" & vote!="-1"
	destring vote, replace
	egen vote_id =  group(session chamber bill motion url) , missing
	bys party vote_id : egen party_mean=mean(vote)
	gen party_vote = 0
	replace party_vote = 1 if party_mean>0
	replace party_vote = -1 if party_mean<0
	gen vote_party_line = vote==party_vote
	gen vote_against_party = vote==-party_vote
	bys vote_id: egen votemargin = mean(vote)
	gen close_floorvotes = floorvotes if abs(votemargin)<.1		
	
	save ../data_output/floorvotes_LA_1997_2016.dta, replace
project, creates(../data_output/floorvotes_LA_1997_2016.dta)	
	
	use ../data_output/floorvotes_LA_1997_2016.dta, clear
	collapse  (mean) vote_party_line vote_against_party (sum) *floorvotes (first) elections_* terms_in_office win TermLengthActual CandName district chamber state party  inoffice year  vtsh, by(CandId term )
	
	save ../data_output/total_floorvotes_LA_1997_2016.dta, replace
project, creates(../data_output/total_floorvotes_LA_1997_2016.dta)	
	
	
